package davidlauzon.activerecord.models;

import java.sql.SQLException;
import java.util.Map;

import davidlauzon.activerecord.ActiveRecord;
import davidlauzon.activerecord.manager.SelectManager;
import davidlauzon.activerecord.nodes.Table;
import davidlauzon.activerecord.nodes.field.Field;
import davidlauzon.activerecord.nodes.field.FloatField;
import davidlauzon.activerecord.nodes.field.IntegerField;
import davidlauzon.activerecord.nodes.field.StringField;


public class Person extends ActiveRecord
{   
    static public final Field ID   = new IntegerField("id", true);
    static public final Field NAME = new StringField("name", false);
    static public final Field SIZE = new FloatField("size", false);
    static public final Field AGE  = new IntegerField("age", false);

    static public final Field[] FIELDS = {ID, NAME, SIZE, AGE};

    
    public Person() {
    }
    
    
    static public Person  build( Map<Field, Object> attributes)                              { return (Person)build(__klass, attributes); }
    static public Person  create(Map<Field, Object> attributes) throws SQLException          { return (Person)create(__klass, attributes); }
    static public boolean update(long id, Map<Field, Object> attributes) throws SQLException { return update(__klass, id, attributes); }
    static public boolean delete(long id) throws SQLException                                { return delete(__klass, id); }
    static public SelectManager find(String condition) throws SQLException                   { return find(__klass,  condition); }
    
    @Override public Table        getTable()          { return DB.PEOPLE_TABLE; }
    @Override public Field[]      getFields()         { return FIELDS; }
    @Override public ActiveRecord getStaticInstance() { return instance; }
    
    static private Class __klass = Person.class;
    
    // MUST BE INSTANCIATED AFTER ALL OTHER VARIABLES
    static public final Person instance = new Person();
}
